package com.scuec.groupfive.controller;

import com.scuec.groupfive.service.SubjectCorrectRateService;
import com.scuec.groupfive.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/subject-stats")
@CrossOrigin
public class SubjectCorrectRateController {

    private final SubjectCorrectRateService subjectCorrectRateService;

    public SubjectCorrectRateController(SubjectCorrectRateService subjectCorrectRateService) {
        this.subjectCorrectRateService = subjectCorrectRateService;
    }

    /**
     * 获取各科目答题正确率统计
     * @return 统一响应结果
     */
    @GetMapping("/correct-rates")
    public Result getSubjectCorrectRates() {
        List<Map<String, Object>> statistics = subjectCorrectRateService.getSubjectCorrectRates();
        return Result.success(statistics);
    }
}